package com.emser.unc.client.presenter;

import com.emser.unc.client.CloudMobile;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

public class LoginPresenter implements Presenter {
	private final Display display;
	
	public interface Display {		    
		HasClickHandlers getLoginButton(); 
		Widget asWidget();
	}
	
	public LoginPresenter(SimpleEventBus eventBus, Display display) {
	    this.display = display;
	    bind();
	}
	
	public void bind() {
	    this.display.getLoginButton().addClickHandler(new ClickHandler() {   
	      public void onClick(ClickEvent event) {
	    	  doLogin();
	      }
	    });   
	}
	
	private void doLogin() {
		Window.Location.assign(CloudMobile.constants.urlServletLogin());
	}
	
	@Override
	public void go(HasWidgets container) {
		container.clear();
	    container.add(display.asWidget());
	}

}
